package com.cqut.hfh.ordering.service.Impl;

import com.cqut.hfh.ordering.pojo.*;
import com.cqut.hfh.ordering.service.IMerchantTypeService;
import com.cqut.hfh.ordering.utils.EntityIdutils;
import com.cqut.li.mybatisutil.dao.base.Dao;
import com.cqut.li.mybatisutil.dao.base.SearchDao;
import com.cqut.li.mybatisutil.entity.base.Entity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * create by gtt on 2019/6/26
 */
@Service
public class MerchantTypeServiceImpl implements IMerchantTypeService {
    @Resource
    private Dao dao;
    @Resource
    private SearchDao searchDao;

    @Override
    public List<MerchantType> getType() {
        return dao.getByCondition("",MerchantType.class);
    }

    @Override
    public List<Map<String, Object>> getMerchantType(String limit, String page) {
        String con = " 1 = 1 limit "
                + (Integer.valueOf(page)-1)*Integer.valueOf(limit) + "," + limit ;
        List<Map<String, Object>> merchanttype_list
                = dao.findByCondition(new String[]{"type_id","type_name",
                        "oper",
                        "optime",
                        "isva","sort"},
                con,
                MerchantType.class);
        return merchanttype_list;
    }

    @Override
    public Integer getCount() {
        return searchDao.sqlCount(Entity.getTableName(MerchantType.class));
    }

    @Override
    public int delById(String typeId) {
        int a = dao.deleteByID(typeId, MerchantType.class);
        String con=" type_id ='" + typeId+"'";
        FoodMerchant foodMerchant=new FoodMerchant();
        foodMerchant.setType_id("");
        int b = dao.updatePropByCondition(foodMerchant,con);
        return a;
    }


    @Override
    public Map<String, Object> findById(String typeId) {
        return dao.getByID(typeId, MerchantType.class).toMap();
    }

    @Override
    public int updateMerchantType(MerchantType merchantType) {
        int a = dao.updatePropByID(merchantType, merchantType.getType_id());
        return a;
    }

    @Override
    public List<Map<String, Object>> getMerchantTypeByName(String limit, String page, String type_name) {
        String con = " type_name like '%" + type_name + "%' limit "
                + (Integer.valueOf(page)-1)*Integer.valueOf(limit) + "," + limit ;
        List<Map<String, Object>> managers_list
                = dao.findByCondition(new String[]{"type_id","type_name",
                        "oper",
                        "optime",
                        "isva","sort"},
                con,
                MerchantType.class);

        return managers_list;
    }

    @Override
    public int saveMerchantType(MerchantType merchantType) {
        int save = dao.save(merchantType);
        return save;
    }
}
